package com.lzy.cloud.goods.facade;

import com.github.pagehelper.PageInfo;
import com.lzy.cloud.goods.dtos.CarCategoryDto;
import com.lzy.cloud.goods.dtos.CarSaleDto;
import com.lzy.cloud.goods.service.CarCategoryService;
import com.lzy.cloud.goods.service.CarSaleService;
import com.lzy.framework.core.ensure.Ensure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WIN7 on 2018/6/11.
 */
@Component
public class CarCategoryFacade {

    @Autowired
    CarCategoryService carCategoryService;

    @Autowired
    CarSaleService carSaleService;

    public Boolean del(String ids) {
        String[] idStrList = ids.split(",");
        for (String id : idStrList) {
            //判断该车型类别是否被占用
            CarSaleDto carSaleDto = new CarSaleDto();
            carSaleDto.setCategoryId(Long.valueOf(id));
            PageInfo<CarSaleDto> pageInfo = carSaleService.selectList(null, carSaleDto);
            if (pageInfo != null && pageInfo.getList() != null) {
                Ensure.that(pageInfo.getList().size()).isNotGt(0, "00030006");
            }
            carCategoryService.delById(Long.valueOf(id));
        }
        return true;
    }

}
